package com.soft.javase.ch06.integer;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/28
 */
public class IntegerDemo2 {
    public static void main(String[] args) {
        System.out.println("---------装箱：int -> Integer----------");
        int i1 = 20;
        Integer integer1 = Integer.valueOf(i1);
        System.out.println(integer1);

        System.out.println("---------拆箱：Integer -> int----------");
        Integer integer2 = new Integer(30);
        int i2 = integer2.intValue();
        System.out.println("i2 = " + i2);

        System.out.println("---------JDK1.5自动拆箱装箱----------");
        int i = 10; //赋值
        Integer integer = i; //装箱
        integer++; //拆箱 运算 装箱
        System.out.println("integer= "+integer);
        Integer in = 20; //装箱

        //public static int parseInt(String s) 将字符串转换成int数据
        String str = "5";
        int int1 = Integer.parseInt(str);
        System.out.println(int1);

        //public static Integer valueOf(String s) 将字符串转换成Integer数据
        Integer int2 = Integer.valueOf(str);
        System.out.println(int2);

        //基本类型转化为String
        int j = 10;
        String string1 = j+"";
        System.out.println("string1="+string1);
        String string2 = String.valueOf(j);
        System.out.println("string2="+string2);

    }
}
